<template>
    <el-container class="home-container">
        <el-header>
            <div>
                <img src="../assets/logo.png"/>
                <span>后台管理系统</span>
            </div>
            <el-button type="info" @click="logout">退出</el-button>
        </el-header>
        <el-container>
            <!--返回结果发-->
            <el-aside :width="isCollapse ? '64px' : '200px'">
                <div class="toggle-button" @click="toggleClapse">||||</div>
                <el-menu
                        background-color="#333744"
                        text-color="#fff"
                        active-text-color="#ffd04b"
                        router
                        unique-opened
                        :collapse="isCollapse"
                        :collapse-transition="false">
                    <el-submenu :index="item.id + ''" v-for="item in menuList" :key="item.id">
                        <template slot="title">
                            <i class="el-icon-location"></i>
                            <span>{{item.name}}</span>
                        </template>
                        <el-menu-item
                                :index="subMenu.url+''"
                                v-for="subMenu in item.children"
                                :key="subMenu.id">
                            <template slot="title">
                                <i class="el-icon-location"></i>
                                <span>{{subMenu.name}}</span>
                            </template>
                        </el-menu-item>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <el-main>
                <router-view v-if="isRouterAlive"/>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
    export default {
        name: "Home",
        data() {
            return {
                menuList: [],
                isCollapse: false,
                isRouterAlive: true,
                formInline: {},
                menuList:{},
                menuList:[],
                pageNum: 1,
                pageSize: 4,
                name: '',//根据权限的名字查询

            }
        },
        methods: {
            toggleClapse() {
                this.isCollapse = !this.isCollapse;
            },
            logout() {

            }
        },
        created() {
            //查询权限及其 子权限 赋值给 menuList
            let url = this.$baseUrl + "/permission/showPermissionMenu";
            this.$axios.get(url)
                .then(res => {
                    this.menuList = res.data.data;
                })
            this.$axios.get(url).then(res => {
                this.menuList = res.data.data;
            })
        }
    }
</script>

<style lang="less" scoped>
    img {
        width: 30px;
        height: 30px;
    }

    .toggle-button {
        background-color: #373d48;
        font-size: 10px;
        text-align: center;
        color: #fff;
        letter-spacing: 0.2em;
        cursor: pointer;
    }

    .el-container {
        .el-header {
            background-color: #373d41;
            display: flex;
            justify-content: space-between;
            padding-left: 0;
            align-items: center;
            color: #fff;
            font-size: 22px;
            div {
                display: flex;
                align-items: center;
                span {
                    margin-left: 14px;
                }
            }
        }
        .el-container {
            .el-container {
                .el-header {
                    background-color: #B3C0D1;
                    color: #333;
                    line-height: 60px;
                }
            }
        }
    }

    .el-aside {
        background-color: #333744;
        .el-menu {
            border-right: 0;
        }

    }

    .el-main {
        background-color: white;
    }

    .home-container {
        height: 100%;
    }

    .router-link-active {
        text-decoration: none;
        text-decoration-color: #ffd04b;
        text-emphasis-color: #fff;
    }

</style>